package com.akk.module.yb.model;

import com.akk.PayConstants;
import com.akk.module.yb.utils.Digest;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.util.ArrayList;
import java.util.List;

public class MerFeeQueryRequest {

    private String mainCustomerNumber; //代理商商户编号
    private String customerNumber;
    private String productType;
    private String hmac;

    public String getMainCustomerNumber() {
        return mainCustomerNumber;
    }

    public void setMainCustomerNumber(String mainCustomerNumber) {
        this.mainCustomerNumber = mainCustomerNumber;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    public String getProductType() {
        return productType;
    }

    public void setProductType(String productType) {
        this.productType = productType;
    }

    public String getHmac() {
        return hmac;
    }

    public void setHmac(String hmac) {
        this.hmac = hmac;
    }

    public static String signature(MerFeeQueryRequest request) {
        StringBuffer sb = new StringBuffer();
        sb.append(request.getCustomerNumber() == null? "":request.getCustomerNumber());
        sb.append(request.getMainCustomerNumber() == null?"":request.getMainCustomerNumber());
        sb.append(request.getProductType() == null?"":request.getProductType());
        return Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY);
    }

    public static Part[] builderPart(MerFeeQueryRequest request) {
        List<Part> parts = new ArrayList<Part>();
        parts.add(new StringPart("mainCustomerNumber",request.getMainCustomerNumber()==null?"":request.getMainCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("customerNumber",request.getCustomerNumber()==null?"":request.getCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("productType",request.getProductType()==null?"":request.getProductType(),"UTF-8"));
        parts.add(new StringPart("hmac",request.getHmac() == null ?"":request.getHmac(),"UTF-8"));
        return parts.toArray(new Part[parts.size()]);
    }

}
